sdk_generate_library()

## These include paths would be exported to project level
sdk_add_include_directories(mbedtls/include)
sdk_add_include_directories(port)
sdk_add_include_directories(port/hw_acc)

## not be exported to project level
sdk_add_private_include_directories(mbedtls/library)

sdk_add_compile_definitions(-DCONFIG_MBEDTLS)
sdk_add_compile_definitions(-DMBEDTLS_CONFIG_FILE=\"mbedtls_sample_config.h\")

sdk_library_add_sources(mbedtls/library/aes.c)
sdk_library_add_sources(mbedtls/library/aesni.c)
sdk_library_add_sources(mbedtls/library/arc4.c)
sdk_library_add_sources(mbedtls/library/aria.c)
sdk_library_add_sources(mbedtls/library/asn1parse.c)
sdk_library_add_sources(mbedtls/library/asn1write.c)
sdk_library_add_sources(mbedtls/library/base64.c)
sdk_library_add_sources(mbedtls/library/blowfish.c)
sdk_library_add_sources(mbedtls/library/camellia.c)
sdk_library_add_sources(mbedtls/library/ccm.c)
sdk_library_add_sources(mbedtls/library/certs.c)
sdk_library_add_sources(mbedtls/library/chacha20.c)
sdk_library_add_sources(mbedtls/library/chachapoly.c)
sdk_library_add_sources(mbedtls/library/cipher.c)
sdk_library_add_sources(mbedtls/library/cipher_wrap.c)
sdk_library_add_sources(mbedtls/library/cmac.c)
sdk_library_add_sources(mbedtls/library/constant_time.c)
sdk_library_add_sources(mbedtls/library/ctr_drbg.c)
sdk_library_add_sources(mbedtls/library/debug.c)
sdk_library_add_sources(mbedtls/library/des.c)
sdk_library_add_sources(mbedtls/library/dhm.c)
sdk_library_add_sources(mbedtls/library/ecdh.c)
sdk_library_add_sources(mbedtls/library/ecdsa.c)
sdk_library_add_sources(mbedtls/library/ecjpake.c)
sdk_library_add_sources(mbedtls/library/ecp.c)
sdk_library_add_sources(mbedtls/library/ecp_curves.c)
sdk_library_add_sources(mbedtls/library/entropy.c)
sdk_library_add_sources(mbedtls/library/entropy_poll.c)
sdk_library_add_sources(mbedtls/library/error.c)
sdk_library_add_sources(mbedtls/library/gcm.c)
sdk_library_add_sources(mbedtls/library/havege.c)
sdk_library_add_sources(mbedtls/library/hkdf.c)
sdk_library_add_sources(mbedtls/library/hmac_drbg.c)
sdk_library_add_sources(mbedtls/library/md2.c)
sdk_library_add_sources(mbedtls/library/md4.c)
sdk_library_add_sources(mbedtls/library/md5.c)
sdk_library_add_sources(mbedtls/library/md.c)
sdk_library_add_sources(mbedtls/library/memory_buffer_alloc.c)
sdk_library_add_sources(mbedtls/library/mps_reader.c)
sdk_library_add_sources(mbedtls/library/mps_trace.c)
sdk_library_add_sources(mbedtls/library/nist_kw.c)
sdk_library_add_sources(mbedtls/library/oid.c)
sdk_library_add_sources(mbedtls/library/padlock.c)
sdk_library_add_sources(mbedtls/library/pem.c)
sdk_library_add_sources(mbedtls/library/pk.c)
sdk_library_add_sources(mbedtls/library/pkparse.c)
sdk_library_add_sources(mbedtls/library/pkcs11.c)
sdk_library_add_sources(mbedtls/library/pkcs12.c)
sdk_library_add_sources(mbedtls/library/pkcs5.c)
sdk_library_add_sources(mbedtls/library/pk_wrap.c)
sdk_library_add_sources(mbedtls/library/pkwrite.c)
sdk_library_add_sources(mbedtls/library/platform.c)
sdk_library_add_sources(mbedtls/library/platform_util.c)
sdk_library_add_sources(mbedtls/library/poly1305.c)
sdk_library_add_sources(mbedtls/library/ripemd160.c)
sdk_library_add_sources(mbedtls/library/rsa.c)
sdk_library_add_sources(mbedtls/library/rsa_internal.c)
sdk_library_add_sources(mbedtls/library/sha1.c)
sdk_library_add_sources(mbedtls/library/sha256.c)
sdk_library_add_sources(mbedtls/library/sha512.c)
sdk_library_add_sources(mbedtls/library/ssl_cache.c)
sdk_library_add_sources(mbedtls/library/ssl_ciphersuites.c)
sdk_library_add_sources(mbedtls/library/ssl_cli.c)
sdk_library_add_sources(mbedtls/library/ssl_cookie.c)
sdk_library_add_sources(mbedtls/library/ssl_msg.c)
sdk_library_add_sources(mbedtls/library/ssl_srv.c)
sdk_library_add_sources(mbedtls/library/ssl_ticket.c)
sdk_library_add_sources(mbedtls/library/ssl_tls13_keys.c)
sdk_library_add_sources(mbedtls/library/ssl_tls.c)
sdk_library_add_sources(mbedtls/library/threading.c)
sdk_library_add_sources(mbedtls/library/timing.c)
sdk_library_add_sources(mbedtls/library/version.c)
sdk_library_add_sources(mbedtls/library/version_features.c)
sdk_library_add_sources(mbedtls/library/x509.c)
sdk_library_add_sources(mbedtls/library/x509_create.c)
sdk_library_add_sources(mbedtls/library/x509_crl.c)
sdk_library_add_sources(mbedtls/library/x509_crt.c)
sdk_library_add_sources(mbedtls/library/x509_csr.c)
sdk_library_add_sources(mbedtls/library/x509write_crt.c)
sdk_library_add_sources(mbedtls/library/x509write_csr.c)
sdk_library_add_sources(mbedtls/library/xtea.c)

if(CONFIG_LWIP)
  sdk_add_compile_definitions(-DMBEDTLS_NET_C)
  sdk_library_add_sources(port/net_sockets.c)
endif()

sdk_library_add_sources(port/entropy_poll_alt.c)

set(MBEDTLS_USE_PKA 0)

# AES HW
if (CONFIG_MBEDTLS_AES_USE_HW)
  sdk_add_compile_definitions(-DCONFIG_MBEDTLS_AES_USE_HW)
  sdk_library_add_sources(port/hw_acc/aes_alt.c)
endif()

# Hash HW
if (CONFIG_MBEDTLS_SHA1_USE_HW)
  sdk_add_compile_definitions(-DCONFIG_MBEDTLS_SHA1_USE_HW)
  sdk_library_add_sources(port/hw_acc/sha1_alt.c)
endif()

if (CONFIG_MBEDTLS_SHA256_USE_HW)
  sdk_add_compile_definitions(-DCONFIG_MBEDTLS_SHA256_USE_HW)
  sdk_library_add_sources(port/hw_acc/sha256_alt.c)
endif()

if (CONFIG_MBEDTLS_SHA512_USE_HW)
  sdk_add_compile_definitions(-DCONFIG_MBEDTLS_SHA512_USE_HW)
  sdk_library_add_sources(port/hw_acc/sha512_alt.c)
endif()

# bignum HW
if (CONFIG_MBEDTLS_BIGNUM_USE_HW)
  set(MBEDTLS_USE_PKA 1)
  sdk_library_add_sources(port/bignum.c)
  sdk_library_add_sources(port/hw_acc/bignum_alt.c)
else()
  sdk_library_add_sources(mbedtls/library/bignum.c)
endif()

# ECC HW
if (CONFIG_MBEDTLS_ECC_USE_HW)
  set(MBEDTLS_USE_PKA 1)
  sdk_add_compile_definitions(-DCONFIG_MBEDTLS_ECC_USE_HW)
  sdk_library_add_sources(port/hw_acc/ecp_alt.c)
  sdk_library_add_sources(port/hw_acc/ecp_curves_alt.c)
endif()

if(MBEDTLS_USE_PKA)
  sdk_library_add_sources(port/hw_acc/bignum_ext.c)
endif()

if (CONFIG_MBEDTLS_SELF_TEST)
  sdk_add_compile_definitions(-DMBEDTLS_SELF_TEST)
endif()

sdk_library_add_sources(port/sec_mutex.c)